#include <iostream>
#include <algorithm>
using namespace std;

int n, m, ans;

typedef struct
{
    int DanJia;    //单价
    int ChanLiang; //产量
} Data;
Data data[5005];
bool cmp(Data a, Data b)
{
    if (a.DanJia == b.DanJia)
        return a.ChanLiang > b.ChanLiang;
    else
        return a.DanJia < b.DanJia;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++)
        cin >> data[i].DanJia >> data[i].ChanLiang;
    sort(data, data + m, cmp);
    // for (int i = 0; i < m; i++)
    int i = 0;
    while (n)
    {
        if (data[i].ChanLiang != 0)
        {
            data[i].ChanLiang -= 1;
            ans += data[i].DanJia;
            n -= 1;
        }
        else
            i++;
    }
    cout << ans;
    return 0;
}